﻿using Newtonsoft.Json;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using WinApp.Model;
using WinApp.Model.AjaxResult;
using WinApp.Until;

namespace WinApp.ViewModel
{
    public class CourseDetailsModel
    {

        public static AjaxResult? GetCourseDetails(TagCourseSessionDto? tagCourseSessionDto)
        {
            AjaxResult result = new AjaxResult();
            if (GlobalVariables.SystemSwitchModel == SwitchMode.OnLine)
            {
                //tagCourseSessionDto.CourseEnrollmentId = 99114895;
                result = WebApiHelper.GetWebAPI<AjaxResult>("api/Admin/Pad/GetMyCourseStructureStatu?enrollmentId=" + tagCourseSessionDto.CourseEnrollmentId);

                //if (result != null && result.Type == AjaxResultType.Success)
                //{
                //    if (result.Data != null && !result.Data.ToString().IsNullOrEmpty())
                //    {


                //    }
                //}
            }
            else
            {
                result.Type = AjaxResultType.Success;
                using (var db = new SqlLiteDbContext())
                {
                    var courseDetails = db.CourseDetails.Where(x => x.EnrollmentId == tagCourseSessionDto.CourseEnrollmentId).Select(x => new MyStructureWithLearningStatuOutPutDto()).ToList();
                    //result.Data = json
                    result.Data = JsonConvert.SerializeObject(courseDetails);
                }

            }
            return result;
        }

    }

    public class MyStructureWithLearningStatuOutPutDto
    {
        public int StructureId { get; set; }
        public bool IsCheckMinimumLearningTime { get; set; }
        public string StructureName { get; set; }

        public string StructureDescription { get; set; }

        public int EnrollmentId { get; set; }

        public double StructureMinimumLearningTime { get; set; }

        public double CumulativeLearningTime { get; set; }
        public int LearningStatu { get; set; }
        public int LearningStatuTableId { get; set; }

        public int? Score { get; set; }

        public int? StructureParentId { get; set; }

        public int? LastLaunchStructureId { get; set; }

        /// <summary>
        /// 含义参看structure表的NodeType
        /// </summary>
        public int NodeType { get; set; }

        public List<MyStructureWithLearningStatuOutPutDto> Children { get; set; } = new List<MyStructureWithLearningStatuOutPutDto>();
        public string CourseUnitLanuchPath { get; set; }
        public int? CourseUnitId { get; set; }
        public int CourseUnitType { get; set; }
        //public int CourseId { get; set; }
        public int? Sequence { get; set; }
        public int CourseUnitCount { get; set; }

        public int CourseId { get; set; }
        /// <summary>
        /// 是否能打开
        /// </summary>
        public bool IsCanOpen { get; set; }
        /// <summary>
        /// 全部满足或任意满足
        /// </summary>
        public string ConditionsOperate { get; set; }
        /// <summary>
        /// 完成条件或者前置条件
        /// </summary>
        public string Conditions { get; set; }
        public string CompletePercent { get; set; }
    }
}
